package com.example.demo.mapper;


import com.example.demo.domain.FileMsg;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface FileMsgMapper {

    @Insert("insert into budget_file_msg" +
            "(id,file_name,file_type,file_size,username,upload_time,path,insert_time)" +
            " values(#{id},#{fileName}" +
            ",#{fileType},#{fileSize},#{userName}" +
            ",#{uploadTime},#{path},#{date})")
    int insertFileMsg(FileMsg file);

    @Results(id="FileMsg",
            value = {
                    @Result(property = "id", column = "ID"),
                    @Result(property = "fileName", column = "FILE_NAME"),
                    @Result(property = "fileType", column = "FILE_TYPE"),
                    @Result(property = "fileSize", column = "FILE_SIZE"),
                    @Result(property = "uploadTime", column = "UPLOAD_TIME"),
                    @Result(property = "path", column = "PATH"),
                    @Result(property = "userName", column = "USERNAME")})
//    @Select("select * from budget_file_msg order by insert_time desc")
    @Select("select *,(select count(*) from budget_file_msg) count from budget_file_msg where username = #{orgid} limit #{start},#{end}")
    List<FileMsg> queryFileList(String orgid,Integer start, Integer end);

    @Results(id="FileMsg1",
            value = {
                    @Result(property = "id", column = "ID"),
                    @Result(property = "fileName", column = "FILE_NAME"),
                    @Result(property = "fileType", column = "FILE_TYPE"),
                    @Result(property = "fileSize", column = "FILE_SIZE"),
                    @Result(property = "uploadTime", column = "UPLOAD_TIME"),
                    @Result(property = "path", column = "PATH"),
                    @Result(property = "userName", column = "USERNAME")})
    @Select("select * from budget_file_msg where file_name like concat('%',concat(#{fileName},'%'))")
    List<FileMsg> queryFileListByFileName(String fileName);

    @Delete("delete from budget_file_msg where file_name=#{fileName}")
    int delete(String fileName);
}
